<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\ViewCount;
use App\Models\User;
//use App\Models\ViewCount;
// 模拟mat 返回的数据
use App\Handlers\GetViewCountHandler;
class ViewsController extends Controller
{
    public function index(Request $request)
    {
      $date = $request->input('end_date');
      $user_ids = $request->input('custom');
      $users = User::find(explode(',', $user_ids));
      //dd($users);
      foreach($users as $user) {
        $viewCount = ViewCount::where('user_id', $user->id)->where('date', $date)->first();
        $counts = rand(1,1000);
        if($viewCount) $counts = $counts + $viewCount->counts;
        $data[$user->id] = [
          str_replace('-', '', $date) => [
            'iv' => $counts
          ],
        ];
      }
      return $data;
    }

    public function zhuaqu(Request $request, GetViewCountHandler $view)
    {
      $date = date('Y-m-d');
      $user_ids = $request->input('user_ids');
      return $view->get($user_ids);
    }
}
